import React, { useEffect } from 'react';

function log(...args) {
  console.log(args.join(', '));
}

function order() {
  log('global start');

  setTimeout(() => {
    log('timeout'); // 等待 promise 微任务执行完成之后最后执行
  }, 0);

  Promise.resolve()
    .then(() => {
      log('p1');
    })
    .then(() => {
      log('p2');
    })
    .then(() => {
      log('p3');
    });

  log('global end');
}

export default function OrderDemo() {
  useEffect(order, []);

  return (
    <div>
      <p>Promise 执行时序</p>
    </div>
  );
}
